<div id="main">
	<div class="hr">
		<hr />
	</div>
	<div id="example">
	<?php
	require 'conn.php';
	$shopId = $_GET['shopid'];
	
	global $query;
	$query = "SELECT * FROM comments";

	if (isset($_GET['page'])) {
		$page = intval($_GET['page']);
	}
	else
	{
		$page = 1;
	}
	$page_count = 0;
	$page_size = $psize;
	$query1 = "SELECT count(*) FROM comments WHERE shop_id=".$shopId;
	$result = mysql_query($query1);
	$row = mysql_fetch_row($result);
	$amount = $row[0];
	if ($amount) {
		if ($amount < $page_size) {
			$page_count = 1;
		}
		if ($amount % $page_size) {
			$page_count = (int)($amount / $page_size) + 1;
		}
		else
		{
			$page_count = $amount / $page_size;
		}
	}
	else
	{
		$page_count = 0;
	}

	echo "<h2> 评论列表 </h2>";
	echo "<blockquote>";
	echo "<p>管理员可以查看和删除以下评论</p>";
	echo "</blockquote>";
	echo "<table border=1>";
	echo "<tr>";
	echo "<td>编号</td>";
	echo "<td>评论内容</td>";
	echo "<td>评论人</td>";
	echo "<td>评论时间</td>";
	echo "<td>操作</td>";
	echo "</tr>";

	if ($amount) {
		$query2 = $query." WHERE shop_id=".$shopId." order by comment_id desc limit ". ($page - 1)*$page_size .", $page_size";
		$result = mysql_query($query2);
		$num = mysql_num_rows($result);
		for ($i = 0; $i < $num; $i++) {
			$row = mysql_fetch_array($result);
			$id = $row['comment_id'];
			$content = $row['content'];
			$createTime = date("y-m-d h:i:s",$row['createtime']);
			
			$userQuery = "SELECT nickname FROM user WHERE uid=".$row['uid'];
			$userResult = mysql_query($userQuery);
			$userRow = mysql_fetch_row($userResult);
			$nickname = $userRow[0];
			
			echo "<tr>";
			echo "<td>".$id."</td>";
			echo "<td>".$content."</td>";
			echo "<td>".$nickname."</td>";
			echo "<td>".$createTime."</td>";
			echo "<td>";
			echo "<form action='deleteComment.php' method='post'>";
			echo "<input type='hidden' name='deleteid' value='$id'/>";
			echo "<input type='hidden' name='shopid' value='$shopId'/>";
			echo "<input type='submit' value='删除'/>";
			echo "</form>";
			echo "</td>";
			echo "</tr>";
		}
		
	}

	else
	{
		echo "没有记录";
	}

	echo "</table>";

	$page_string = '';
	if ($page == 1) {
		$page_string .= '第一页|上一页';
	}
	else
	{
		$page_string .= '<a href=?page=1&shopid='.$shopId.'>第一页</a>|<a href=?page='.($page - 1).'&shopid='.$shopId.'>上一页</a>|';
	}
	if (($page == $page_count) || ($page_count == 0)) {
		$page_string .= '下一页|尾页';
	}
	else
	{
		$page_string .= '<a href=?page='.($page + 1).'&shopid='.$shopId.'>下一页</a>|<a href=?page='.$page_count.'&shopid='.$shopId.'>尾页</a>|';
	}
	echo "<br>".$page_string;
	?>

	</div>
</div>